package org.hum.scaffold.mongodb;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;
import org.springframework.test.context.junit4.SpringRunner;

@Component
@RunWith(SpringRunner.class)
@SpringBootApplication
public class MongodbTest {

	@Autowired
	private MongoTemplate mongoTemplate;
	
	@Test
	public void test1() {

//		mongoTemplate.save(new User2(1L, 20, "zhangsan"));
//		mongoTemplate.save(new User2(2L, 30, "lisi"));
//		mongoTemplate.save(new User2(3L, 40, "wangwu"));
//		mongoTemplate.save(new User2(4L, 50, "maliu"));
//		mongoTemplate.save(new User2(5L, 60, "Jim"));
//		mongoTemplate.save(new User(6L, "Black"));
		
		System.out.println("111111");
		Query query = new Query();
		Criteria criteria = Criteria.where("id").gt(3);
		query.addCriteria(criteria);
		List<User2> list = mongoTemplate.find(query, User2.class);
		System.out.println(list);
		System.out.println("222222");
	}
}
